package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.WmNewsDto;
import com.heima.media.dto.WmNewsPageDto;
import com.heima.media.entity.WmNews;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.heima.media.service.IWmNewsService;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author itheima
 * @since 2022-07-29
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
@CrossOrigin
public class WmNewsController{

    @Autowired
    private IWmNewsService wmNewsService;

    /**
     * 分页查询当前自媒体文章列表
     *
     * @param wmNewsPageDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult listByCondition(@RequestBody WmNewsPageDto wmNewsPageDto){
        return wmNewsService.listByCondition(wmNewsPageDto);
    }

    /**
     * 自媒体文章提交审核
     * @param wmNewsDto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto){

        return wmNewsService.submit(wmNewsDto);

    }

    @GetMapping("/{id}")
    public ResponseResult getById(@PathVariable("id") Integer id){
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }

    /**
     * 修改文章上下架状态
     * @param dto
     * @return
     */
    @PutMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto){
        return wmNewsService.downOrUp(dto);
    }
}
